/**
 * Created by Junchuan.Wu on 2015/11/20 0020.
 * 拖放功能的实现
 */
/*监听拖动事件*/
var dragSrc = null;
/*设置DragIcon*/
var dragIcon = document.createElement('img');

/*E:\hbuilder_work\FinalExam4Html\img\googlelogo_color_272x92.png*/
dragIcon.src = 'img/googlelogo_color_272x92.png';

/*开始拖动 dragstart*/
function handleDragStar(e) {
    e.dataTransfer.effectAllowed = 'move';
    e.dataTransfer.setData('text/html', this.innerHTML);
    e.dataTransfer.setDragImage(dragIcon, -10, -10);
    this.classList.add('moving');
    dragSrc = this;
}

/*dragenter*/
function handleDragEnter(e) {
    this.classList.add('over');
}

/*drageover*/
function handleDragOver(e) {
}
/*dragleave*/
function handleDragLeave(e) {
    this.classList.remove('over');
    this.classList.remove('moving');
}
/*drop*/
function handleDrop(e) {
    e.stopPropagation();
    e.preventDefault();
    if (dragSrc != this) {
        dragSrc.innerHTML = this.innerHTML;
        this.innerHTML = e.dataTransfer.getData('text/html');
    }
}

/*阻止默认行为*/
document.ondragover = function (e) {
    e.preventDefault();
};
document.ondrop = function (e) {
    e.preventDefault();
};
